Skip to content

Remove process env mutation (#177) (#221) - #223

Draft
leynos wants to merge 3 commits into
feat/align-workspace-lint-policyfrom
issue-177-221-remove-in-process-env-mutation
Draft

Remove process env mutation (#177) (#221)#223
leynos wants to merge 3 commits into
feat/align-workspace-lint-policyfrom
issue-177-221-remove-in-process-env-mutation

Conversation

@leynos

@leynos leynos commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

This change removes process-global environment mutation from the HNSW property
tests. Configuration now flows through injected mockable::Env objects, and
tests use MockEnv, so they can execute independently and in parallel.

It applies the same injection boundary to the workspace remaining
environment-variable readers and denies direct std::env methods that would
bypass it.

Closes #177
Closes #221

Review walkthrough

Validation

  • make check-fmt
  • make test (1,082 passed; 1 skipped)
  • make typecheck
  • make lint
  • make markdownlint
  • make nixie
  • coderabbit review --agent --committed --base origin/feat/align-workspace-lint-policy (0 findings)

References

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Warning

Your free Security trial is over. An organization admin can activate billing to continue.


Comment @coderabbitai help to get the list of available commands.

codescene-access[bot]

This comment was marked as outdated.

@leynos
leynos force-pushed the issue-177-221-remove-in-process-env-mutation branch from aaacec5 to 519396a Compare August 24, 2026 13:44
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No quality gates enabled for this code.

@sourcery-ai

sourcery-ai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR establishes mockable::Env as the workspace boundary for environment-variable access, using DefaultEnv in production and MockEnv in tests; HNSW property tests no longer mutate process-global state, remaining readers are migrated, and Clippy now prevents direct reads or mutations from being reintroduced.

Sequence diagram for injected environment configuration

sequenceDiagram
    participant EntryPoint
    participant Env as mockable::Env
    participant Configuration

    EntryPoint->>Configuration: load_with_env(Env)
    Configuration->>Env: string(variable)
    Env-->>Configuration: configured value or None
    Configuration-->>EntryPoint: resolved configuration

    Note over EntryPoint,Env: Production supplies DefaultEnv, tests supply MockEnv
Loading

File-Level Changes

Change Details Files
Introduces dependency-injected environment access across runtime, benchmark, CI, and test-support code.
  • Adds mockable and uses DefaultEnv at production entry points.
  • Threads &dyn Env through environment-dependent helpers.
  • Preserves existing defaults, parsing, and error handling while replacing direct reads with string, os_string, or raw access.
Cargo.toml
chutoro-benches/Cargo.toml
chutoro-benches/benches/hnsw.rs
chutoro-benches/benches/hnsw_ef_sweep.rs
chutoro-benches/src/criterion_support.rs
chutoro-benches/src/neighbour_scoring/benchmark_runner.rs
chutoro-benches/src/neighbour_scoring/build_profile.rs
chutoro-benches/src/source/mnist/mod.rs
chutoro-cli/Cargo.toml
chutoro-cli/src/logging.rs
chutoro-core/src/mst/property/types.rs
chutoro-providers/dense/Cargo.toml
chutoro-providers/dense/build.rs
chutoro-test-support/Cargo.toml
chutoro-test-support/src/bin/benchmark_regression_gate.rs
chutoro-test-support/src/bin/kani_nightly_gate.rs
chutoro-test-support/src/ci/benchmark_regression_profile.rs
chutoro-test-support/src/ci/property_test_profile.rs
chutoro-test-support/tests/benchmark_regression_gate_cli.rs
chutoro-test-support/tests/kani_nightly_gate_cli.rs
Removes process-global environment mutation from HNSW property tests and replaces serialized real-environment tests with isolated mocks.
  • Adds an injectable search-property configuration seam with DefaultEnv for production and MockEnv for tests.
  • Rewrites unset, valid, and invalid override tests without set_var, remove_var, or a global mutex.
  • Adds injectable coverage detection and MST concurrency configuration loading.
chutoro-core/Cargo.toml
chutoro-core/src/hnsw/tests/property/search_config.rs
chutoro-core/src/hnsw/tests/support.rs
chutoro-core/src/mst/property/types.rs
Enforces the environment-access boundary through workspace lint policy.
  • Denies direct std::env variable reads and process mutation via Clippy.
  • Applies the deny lint to benchmark targets as well as workspace lints.
  • Retains narrowly scoped std::env usage for supported operations such as arguments, temp directories, and error types.
clippy.toml
Cargo.toml
chutoro-benches/Cargo.toml
Updates environment-driven test-support profiles and their tests to use mockable environments.
  • Replaces generic lookup closures with Env injection in property-test and benchmark-regression profile loaders.
  • Uses MockEnv in profile unit tests for deterministic, parallel-safe cases.
  • Routes CLI integration-test binary discovery through DefaultEnv.
chutoro-test-support/src/ci/property_test_profile.rs
chutoro-test-support/src/ci/benchmark_regression_profile.rs
chutoro-test-support/tests/benchmark_regression_gate_cli.rs
chutoro-test-support/tests/kani_nightly_gate_cli.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#177 Rework the HNSW search configuration property tests so configuration is supplied through an injected environment seam rather than process-global environment access.
#177 Remove the local ENV_LOCK and every unsafe std::env::set_var or std::env::remove_var call from search_config.rs.
#177 Ensure the workspace no longer permits direct environment reads or mutations that bypass the injection boundary, allowing the property tests to run in parallel without global environment serialization.
#221 Refactor the HNSW search-configuration loader to use an injected environment reader, with production code using the real environment and tests using isolated stubs instead of process-global mutation.
#221 Remove the HNSW tests' in-process environment mutations, mutex guard, unsafe blocks, and global-state coupling while preserving coverage of unset, valid, and invalid environment values.
#221 Add a workspace Clippy policy that denies direct std::env variable reads and mutation methods, preventing the prohibited pattern from returning.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

leynos added 3 commits August 24, 2026 18:04
Replace process-global HNSW test mutation with MockEnv-backed configuration
injection, so property tests can run concurrently without unsafe access.

Route environment-variable reads through mockable::Env across the workspace
and deny the direct std::env methods to prevent regression.
Regenerate the lockfile for the lint-policy branch dependency graph and
resolve the rebased test configuration lint findings. Record the isolated
property-test timeout experiment and the shared test-binary reader decision
for the active lint-policy plan.
Keep the parent branch's `map_or` policy parsing while preserving the
injected mockable environment reader. The previous rebase replay left both
loader bodies in the implementation block, preventing the test-support
crate from compiling.
@leynos
leynos force-pushed the issue-177-221-remove-in-process-env-mutation branch from 519396a to f3c778f Compare August 24, 2026 16:27
@leynos
leynos changed the base branch from main to feat/align-workspace-lint-policy August 24, 2026 16:27

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Improved (1 files improve in Code Health)

Gates Failed
Enforce advisory code health rules (1 file with String Heavy Function Arguments)

Our agent can fix these. Install it.

Gates Passed
5 Quality Gates Passed

Reason for failure
Enforce advisory code health rules Violations Code Health Impact
process.rs 1 advisory rule 9.69 Suppress

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
tests.rs 9.39 → 10.00 Code Duplication

Absence of Expected Change Pattern

  • chutoro/chutoro-core/src/hnsw/tests/property/types.rs is usually changed with: chutoro/chutoro-core/src/hnsw/tests/property/strategies.rs
  • chutoro/chutoro-providers/dense/src/simd/tests.rs is usually changed with: chutoro/chutoro-providers/dense/src/simd/kernels.rs

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@leynos

leynos commented Aug 26, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Ensure that this is validated against the current version of the codegraph.

If further refinement to address this finding would be deleterious, please supply a clear explanatory one to two paragraph markdown message in a code block that I can paste into the CodeScene web ui's diagnostic suppression function so this diagnostic can be silenced.

String Heavy Function Arguments

chutoro-test-support/src/process.rs:

What lead to degradation?

In this module, 41.7% of all arguments to its 7 functions are strings. The threshold for string arguments is 39.0%

Why does this problem occur?

String is a generic type that fail to capture the constraints of the domain object it represents. In this module, 42 % of all function arguments are string types.

How to fix it?

Heavy string usage indicates a missing domain language. Introduce data types that encapsulate the semantics. For example, a user_name is better represented as a constrained User type rather than a pure string, which could be anything.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== target module outline =='
ast-grep outline chutoro-test-support/src/process.rs --items all || true

printf '%s\n' '== target module =='
cat -n chutoro-test-support/src/process.rs

printf '%s\n' '== process module references and candidate call sites =='
rg -n -C 4 --glob '*.rs' \
  '(?:use\s+.*\bprocess\b|process::|(?:run|run_with|spawn|command|assert).*\()' \
  . || true

printf '%s\n' '== tests and exports around target module =='
rg -n -C 4 --glob '*.rs' \
  '(?:mod\s+process\b|pub\s+(?:use|mod)\s+process\b|#\[(?:test|tokio::test)\])' \
  chutoro-test-support . || true

printf '%s\n' '== workspace package metadata =='
fd -a '^Cargo\.toml$' . -x sh -c 'printf "\n== %s ==\n" "$1"; sed -n "1,160p" "$1"' sh {} \; || true

Length of output: 175151


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== chutoro-test-support/src/process.rs =='
cat -n chutoro-test-support/src/process.rs

printf '%s\n' '== public declarations in target module =='
rg -n -C 2 '^\s*pub(?:\([^)]*\))?\s+(?:struct|enum|type|fn|trait|const|static)\b' \
  chutoro-test-support/src/process.rs || true

printf '%s\n' '== imports or qualified references to chutoro_test_support::process =='
rg -n -C 3 --glob '*.rs' \
  '(?:chutoro_test_support::process|use\s+chutoro_test_support::\{?[^;]*\bprocess\b|use\s+chutoro_test_support::process)' \
  . || true

printf '%s\n' '== target-module test declarations =='
rg -n -C 5 '^\s*(?:#\[(?:test|rstest[^\]]*)\]|fn\s+\w+)' \
  chutoro-test-support/src/process.rs || true

Length of output: 11609


@leynos chutoro-test-support/src/process.rsfind_test_binary, find_test_binary_with_env, find_in_deps, is_matching_binary, has_expected_suffix

Suppress this diagnostic. The current codegraph has one public API, find_test_binary(name: &str). Its only consumers are chutoro-test-support/tests/benchmark_regression_gate_cli.rs and chutoro-test-support/tests/kani_nightly_gate_cli.rs. The name arguments identify Cargo [[bin]] targets. The file_name argument is a transient UTF-8 file-system component used only to test the executable suffix.

Do not introduce a TestBinaryName newtype. It would add conversion and forwarding code to a small test-support boundary. It would not add meaningful validation because Cargo defines binary-name validity and the file system defines file names. The current &str parameters accurately support Cargo environment-variable construction, target-path construction, and prefix matching. No AI coding-agent prompt is appropriate because the refactor would be deleterious.

Paste this into the CodeScene diagnostic suppression field:

This module resolves Cargo binary target names and executable file names. The `&str` values are not separate domain entities. They are representations of one externally defined identifier: the Cargo `[[bin]]` name, plus a transient file-name view required for executable-suffix matching.

Introducing a newtype would add conversion and forwarding code without introducing useful validation or preventing invalid states. Cargo owns binary-name semantics, and the file system owns file-name semantics. Keep the small test-support API and its private helpers string-based.

You are interacting with an AI system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant